package com.proyecto.poo;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CirculoRes extends Activity {
	float radio=0f;
	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.circuloresult);
        
        
        TextView texto = (TextView)findViewById(R.id.textView1);
        
        float area=0f;
        float perimetro=0f;
        String restext;
        
        
        //Nuevo bundle para recibir los parametros enviados por la actividad anterior
        Bundle extras = getIntent().getExtras();
        if(extras !=null)
        {
         radio = extras.getFloat("radioCirculo");
        }
        
        area=(float) (Math.PI*(radio)*(radio));
        perimetro=(float) (Math.PI*(radio*2));
        restext="Area: "+Float.toString(area)+" Unidades\nPerimetro: "+Float.toString(perimetro)+" Unidades";
        try{
        texto.setText(restext);
        }catch(Exception c){}  
        
        LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linearLayout1);
        Lienzo fondo=new Lienzo(this);        
        linearLayout.addView(fondo);

    }
    
    //Neva clase usada para poder dibujar en el layout con el metodo onDraw
    class Lienzo extends View {
    	
        public Lienzo(Context context) {
            super(context);
        }
        
        protected void onDraw(Canvas canvas) {

            Paint pincel1=new Paint();
            pincel1.setStrokeWidth(3);
            pincel1.setARGB(130,116,183,252);
            pincel1.setTextSize(15);
            canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, radio, pincel1);
            pincel1.setARGB(255,255,255,255);
            canvas.drawLine(canvas.getWidth()/2, (canvas.getHeight()/2)-radio-5, (canvas.getWidth()/2)+radio, (canvas.getHeight()/2)-radio-5, pincel1);
            canvas.drawText(""+radio+" Unidades", canvas.getWidth()/2, (canvas.getHeight()/2)-radio-7, pincel1);
        }
    }  


}
